using XinBang.Entity;
using XinBang.BLL;
using System.Collections.Generic;

namespace XinBang.ShoppingCart
{
    public class RecordUtil
    {
        private static GoodsBL gb = new GoodsBL();
        public static IList<ShoppingCartRecord> ConvertShoppingCartToRecord()
        {
            Cart sc = Cart.GetShoppingCart();
            IList<ShoppingCartRecord> list = new List<ShoppingCartRecord>();
            foreach (KeyValuePair<int,int> item in sc.GetDictionary())
            {
                ShoppingCartRecord record = new ShoppingCartRecord();
                Goods goods = gb.GetGoodsById(item.Key);
                record.Gooid = goods;
                record.Amount = item.Value;
                record.GoodsPrice = goods.Price;
                list.Add(record);
            }
            return list;
        }

        public static IList<Record> ConvertShoppingCartRecordList()
        {
            Cart sc = Cart.GetShoppingCart();
            IList<Record> list = new List<Record>();
            foreach (KeyValuePair<int, int> item in sc.GetDictionary())
            {
                Record record = new Record();
                Goods goods = gb.GetGoodsById(item.Key);
                record.Gooid = goods;
                record.Amount = item.Value;
                record.GoodsPrice = goods.Price;
                list.Add(record);
            }
            return list;
        }

        public static IList<ShoppingCartRecord> ConvertRecordListToShoppingCartRecordList(IList<Record> list)
        {
            IList<ShoppingCartRecord> recordList = new List<ShoppingCartRecord>();
            foreach (Record record in list)
            {
                ShoppingCartRecord scr = new ShoppingCartRecord(record);
                recordList.Add(scr);
            }
            return recordList;
        }

        public class ShoppingCartRecord : Record
        {
            public ShoppingCartRecord()
            {

            }
            public ShoppingCartRecord(Record record)
            {
                this.Recid = record.Recid;
                this.GoodsPrice = record.GoodsPrice;
                this.Amount = record.Amount;
                this.Gooid = record.Gooid;
                this.Ordid = record.Ordid;
            }

            public decimal Total
            {
                get { return this.GoodsPrice* this.Amount; }
            }

            public int Cent
            {
                get { return this.Gooid.Cent * this.Amount; }
            }

            public int GoodsId
            {
                get { return this.Gooid.Gooid; }
            }
        }

        
    }
}
